package com.ccsoft.zknote.enums;

/**
 * @author chanchaw
 * @create 2023-07-09 08:26
 */
public enum EventCode {
    // 1开头表示系统
    LOGIN_SUCCESS(1001,1001,"LOGIN_SUCCESS","登录成功"),
    LOGIN_FAIL(1002,1002,"LOGIN_FAIL","登录失败"),
    LOGIN_LOG_CREATE_FAIL(1003,1003,"LOGIN_LOG_CREATE_FAIL","登录日志创建失败"),
    LOGIN_LOG_CREATE_EXCEPTION(1004,1004,"LOGIN_LOG_CREATE_EXCEPTION","登录日志创建异常"),
    LOGIN_SAVE_USER_TOKEN_REDIS_EXCEPTION(1005,1005,"LOGIN_SAVE_USER_TOKEN_REDIS_EXCEPTION","登录成功但写入redis失败"),

    // ------------------ SQL 状态 -----------------------------------------
    QUERY_SUCCESS(2001,2001,"QUERY_SUCCESS","查询成功"),
    QUERY_EXCEPTION(2002,2002,"QUERY_EXCEPTION","查询异常"),// DB报出查询异常
    QUERY_ERROR(2003,2003,"QUERY_ERROR","查询出错"),// 查询结果和预期不一致 - 应一条数据，结果返回多条
    QUERY_NONE(2004,2004,"QUERY_NONE","没有查询到数据"),

    // ------------------ 账号状态 -----------------------------------------
    ACCOUNT_LOCKED(3001,3001,"ACCOUNT_LOCKED","账号被锁定"),
    ACCOUNT_NOT_EXISTS(3002,3002,"ACCOUNT_NOT_EXISTS","账号不存在"),
    ACCOUNT_EMAIL_EMPTY(3003,3003,"ACCOUNT_EMAIL_EMPTY","邮箱为空"),
    ACCOUNT_PASSWORD_EMPTY(3004,3004,"ACCOUNT_PASSWORD_EMPTY","密码为空"),
    ;
    private int index;
    private Integer code;
    private String flag;
    private String desc;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    // 通过枚举值获取索引
    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    EventCode(int index,Integer code, String flag, String desc) {
        this.index = index;
        this.desc = desc;
        this.flag = flag;
        this.code = code;
    }

    // 根据索引返回枚举值
    static EventCode of(int index){
        for(EventCode item:EventCode.values()){
            if(item.getIndex() == index) return item;
        }
        return null;
    }

    public String toString(){
        return this.code + ","+this.flag+","+this.desc;
    }
}
